<template>
  <div>
    <el-container>
      <!--侧边栏-->
      <el-aside :width="asidWidth" style="min-height: 100vh;background-color:#001529 ">
        <div
            style="height: 60px;background-color: black;color: white;display: flex;align-content: center;justify-content: center">
          <img src="@/assets/logo1.png" alt="" style="width: 40px;height: 40px;margin-top: 5px">
          <span class="logo-title" style="margin-left: 5px;font-size: 20px;margin-top: 12px" v-show="!isCollapse">凌云2024.V1</span>
        </div>

        <el-menu :default-opends="['info']" :collapse="isCollapse" router background-color="#001529" text-color="rgba(255,255,255,0.65)"
                 active-text-color="#fff" style="border: none" :default-active="$route.path">
          <!--去掉菜单栏的边框-->
          <!--
          router：给定一个点击效果
          :default-active="$route.path给当前访问路径的路由指定一个高亮的效果
          active-text-color="#fff"设置高亮颜色
          -->
          <el-menu-item index="/home">
            <template>
              <i class="el-icon-s-home"></i>
              <span>系统首页</span>
            </template>
          </el-menu-item>
          <!--二级菜单-->
          <el-submenu index="info" v-if="user.role==='管理员'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/user" v-if="user.role==='管理员'">用户信息</el-menu-item>
            <el-menu-item index="/news" >新闻信息</el-menu-item>
            <el-menu-item index="/notice" v-if="user.role==='管理员'">系统公告</el-menu-item>
            <el-menu-item index="/charts" v-if="user.role==='管理员'">数据统计</el-menu-item>
            <el-menu-item index="/orders" v-if="user.role==='管理员'">订单管理</el-menu-item>

          </el-submenu>
        </el-menu>
      </el-aside>


      <el-container>
        <!--头部区域-->
        <el-header>
          <i :class="collapseIcon" style="font-size: 26px" @click="handleCollapse"></i>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px">
            <el-breadcrumb-item :to="{ path: '/' }">主页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: $router.path }">{{$route.meta.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div style="flex: 1;width: 0;display:flex;align-items: center;justify-content: flex-end">
            <el-dropdown placement="bottom">
              <div style="display: flex;align-items: center;cursor: default">
                <img :src="user.avatar" alt="" style="width: 40px;height: 40px;border-radius: 50%">
                <span>{{user.name}}</span>
              </div>

              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="$router.push('/person')">个人信息</el-dropdown-item>
                <el-dropdown-item @click.native="$router.push('/password')">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <!--主题区域        -->
        <el-main>
         <router-view @update:user="updateUser"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>

import request from "@/untils/request"

export default {
  name: 'HomeView',
  data() {
    return {
      isCollapse: false,
      asidWidth: '200px',
      collapseIcon: 'el-icon-s-fold',
      user: JSON.parse(localStorage.getItem("honey-user") || '{}'),
    }
  },
  mounted() {
    console.log(this.$router)


    /*  res.data={  //数据的格式
       code: '200',
       msg: '请求成功'
       data:{
       }
     }*/
    /*axios.get('http://localhost:8081/user/selectAll').then(res=>{
      console.log(res.data)//拿到后台返回的数据
      this.users=res.data.data
    })
    axios.get('http://localhost:8081/user/SeletcById/17').then(res=>{
      console.log(res.data)//拿到后台返回的数据
      this.users=res.data.data
    })*/
  },
  methods: {
    updateUser(user){
      this.user=JSON.parse(JSON.stringify(user))
    },
    logout() {
      localStorage.removeItem("honey-user")//清楚当前用户的数据
      this.$router.push("login")
    },
    handleCollapse() {
      this.isCollapse = !this.isCollapse
      this.asidWidth = this.isCollapse ? '64px' : '200px'
      this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    }
  }
}
</script>


<style>
.el-menu--inline .el-menu-item {
  /*给二级字菜单设置颜色*/
  background-color: #000c17 !important;
  padding-left: 49px !important;
}

.el-menu-item:hover, .el-submenu__title:hover {
  color: #fff !important;
}

.el-submenu__title:hover i {
  color: white !important;
}

.el-menu-item.is-active {
  background-color: #1890ff !important;
  border-radius: 5px !important;
  width: calc(100% - 8px);
  margin-left: 4px;

}

.el-menu-item.is-active i, .el-menu-item.is-active .el-tooltip {
  margin-left: -4px !important;
}

.el-menu-item {
  height: 40px !important;
  line-height: 40px !important;

}

.el-submenu__title {
  height: 40px !important;
  line-height: 40px !important;
}

.el-menu--inline {
  color: white !important;
}

.el-submenu .el-menu-item {
  min-width: 0 !important;
}

.el-menu--inline .el-menu-item.is-active {
  padding-left: 45px !important;
}

.logo-title {
  margin-left: 5px;
  font-size: 20px;
  transition: all .3s;
}

.el-aside {
  transition: width .3s;
  box-shadow: 2px 0 6px rgba(0, 21, 41, 35);
}

.el-header {
  box-shadow: 2px 0 6px rgba(0, 21, 41, 35);
  display: flex;
  align-items: center;
}
</style>
